package com.handu.luna.core.domain;

import java.io.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import com.handu.luna.core.domain.admin.AdminControllerCategory;
import com.handu.luna.core.domain.admin.AdminControllerDescription;
import com.handu.luna.core.domain.admin.Operator;
import com.handu.luna.core.domain.advertisement.AdPositionId;
import com.handu.luna.core.domain.advertisement.AdPositionId.BelongPage;
import com.handu.luna.core.domain.advertisement.AdvertiseList.MediaType;
import com.handu.luna.core.domain.advertisement.AdvertiseList;
import com.handu.luna.core.domain.article.ArticleCategory;
import com.handu.luna.core.domain.article.ArticleList;
import com.handu.luna.core.domain.goods.Attribute;
import com.handu.luna.core.domain.goods.Attribute.SelectType;
import com.handu.luna.core.domain.goods.Brand;
import com.handu.luna.core.domain.goods.Brand.BrandType;
import com.handu.luna.core.domain.goods.BrandGeneralInfo;
import com.handu.luna.core.domain.goods.Category;
import com.handu.luna.core.domain.goods.Goods;
import com.handu.luna.core.domain.order.OrderDetail;
import com.handu.luna.core.domain.order.OrderInfo;
import com.handu.luna.core.domain.order.OrderInfo.DeliveryStatus;
import com.handu.luna.core.domain.order.OrderInfo.OrderSource;
import com.handu.luna.core.domain.order.OrderInfo.OrderStatus;
import com.handu.luna.core.domain.order.OrderInfo.PaymentStatus;
import com.handu.luna.core.domain.promotion.*;
import com.handu.luna.core.domain.promotion.Activities.ActivitiesMethods;
import com.handu.luna.core.domain.promotion.Activities.ActivitiesRange;
import com.handu.luna.core.domain.promotion.PostForFreeActivity.PostForFreeType;
import com.handu.luna.core.domain.system.Deliver;
import com.handu.luna.core.domain.system.DeliverArea;
import com.handu.luna.core.domain.system.Region;
import com.handu.luna.core.domain.user.User;
import com.handu.luna.core.domain.user.User.UserStatus;
import com.handu.luna.core.domain.user.UserRank;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.yaml.snakeyaml.Yaml;

public class Seed {
	
	protected Log logger = LogFactory.getLog(this.getClass());
	
	Context context;
	public Seed(Context context){
		this.context = context;
	}
	
	public void init() {
		createUserRank();
		createUsers();	
		createBrands();
		createCategorys();
		createTopics();
		createAttributes();
		createGeneralInfos();
		createArticleCategory();
		createArticleList();
		createGoodsManage();
		createAdminControllers();
        createCouponPromotions();
        createCoupons();
        createSalesPromotion();
        createSecKillGroupBuy();
        createActivities();
        createOrders();
        createPostCardPromotions();
        createPostCards();
        createRedPacketPromotions();
        createRedPackets();
        createAdPositionId();
        createAdvertiseList();
        createRegions();
        createDeliverAreas();    
        createPostForFreeActivity();
        createDelivers();
        createOperator();
        createCashCardPromotions();
        createCashCards();
	}
	
	private void createUsers(){
		List<User> users = new ArrayList<User>();
		users.add(new User("晨晨00", "123123", "qihu_00@hstyle.com","0", "13111111101","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨01", "123123", "qihu_01@hstyle.com","0", "13111111102","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨02", "123123", "qihu_02@hstyle.com","0", "13111111103","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨03", "123123", "qihu_03@hstyle.com","0", "13111111104","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨04", "123123", "qihu_04@hstyle.com","0", "13111111105","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨05", "123123", "qihu_05@hstyle.com","0", "13111111106","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨06", "123123", "qihu_06@hstyle.com","0", "13111111107","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨07", "123123", "qihu_07@hstyle.com","0", "13111111108","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨08", "123123", "qihu_08@hstyle.com","0", "13111111109","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨09", "123123", "qihu_09@hstyle.com","0", "13111111110","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨010", "123123", "qihu_010@hstyle.com","0", "13111111111","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨11", "123123", "qihu_11@hstyle.com","0", "13111111112","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨12", "123123", "qihu_12@hstyle.com","0", "13111111113","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨13", "123123", "qihu_13@hstyle.com","0", "13111111114","否", "否", 0, 0, UserStatus.NORMAL));
		users.add(new User("晨晨14", "123123", "qihu_14@hstyle.com","0", "13111111115","否", "否", 0, 0, UserStatus.NORMAL));
		
		users.forEach(each -> context.getUserRepository().save(each));
	}
	
	private void createUserRank(){
		List<UserRank> userRank = new ArrayList<UserRank>();
		userRank.add(new UserRank("普通会员", 1, 100, false));
		userRank.add(new UserRank("铜牌会员", 101, 500, false));
		userRank.add(new UserRank("银牌会员", 501, 1000, false));
		userRank.add(new UserRank("金牌会员", 1001, 5000, false));
		userRank.add(new UserRank("特殊会员1", 1, 1, true));
		userRank.add(new UserRank("特殊会员2", 1, 1, true));
		userRank.add(new UserRank("特殊会员3", 1, 1, true));
		userRank.add(new UserRank("特殊会员4", 1, 1, true));
		userRank.forEach(each -> context.getUserRankRepository().save(each));
	}
	
	private void createBrands(){
		List<Brand> brands = new ArrayList<Brand>();
		brands.add(new Brand("HSTYLE","女装","http://www.handu.com",10,true , BrandType.AGENT));
		brands.add(new Brand("AMH","男装","http://www.handu.com",6,true,BrandType.AGENT));
		brands.add(new Brand("SONEED","soneed","http://www.handu.com",8,true,BrandType.AGENT));
		brands.add(new Brand("sulv","sulv","http://www.handu.com",3,true));
		brands.add(new Brand("aaaa","","http://www.handu.com",5,false));
		brands.add(new Brand("minizaru","童装","http://www.handu.com",9,true));
		
		brands.forEach(each -> context.getBrandRepository().save(each));
	}	

	private void createCategorys(){
		List<Category> list=new ArrayList<Category>();
		
		list.add(new Category(1,"", "女装",0, 1,true,true,1) );
		list.add(new Category(2,"1", "女T恤",1, 13,true,true,2) );
		list.add(new Category(3,"", "男装",0,4,true,true,3) );
		list.add(new Category(4,"1", "连衣裙",1,3,true,true,2) );
		list.add(new Category(5,"3", "衬衣",3, 1,true,true,3) );
		
		list.forEach(each -> context.getCategoryRepository().save(each));
	}
	
	private void createArticleCategory(){  //帮助中心 文章分类
		List<ArticleCategory> list = new ArrayList<ArticleCategory>();
		list.add(new ArticleCategory(1,"关于韩都",0,"",50,true,"帮助中心","帮助中心"));
		list.add(new ArticleCategory(2,"新手指南",1,"1",60,false,"关于用户注册","关于用户注册"));
		list.add(new ArticleCategory(3,"支付方式",1,"1",70,true,"关于支付方式","关于支付方式"));
		list.add(new ArticleCategory(4,"配送方式",1,"1",80,false,"关于配送方式","关于配送方式"));
		list.add(new ArticleCategory(5,"三级分类--新手指南",2,"1,2",50,true,"帮助中心","帮助中心"));
		list.add(new ArticleCategory(6,"三级分类--支付方式",3,"1,3",50,true,"帮助中心","帮助中心"));
		list.add(new ArticleCategory(7,"三级分类--配送方式",4,"1,4",50,true,"帮助中心","帮助中心"));
		list.add(new ArticleCategory(8,"四级分类--新手指南--新手指南",5,"1,2,5",50,true,"帮助中心","帮助中心"));
		list.add(new ArticleCategory(9,"四级分类--支付方式--支付方式",6,"1,3,6",50,true,"帮助中心","帮助中心"));
		list.add(new ArticleCategory(10,"四级分类--配送方式--配送方式",7,"1,4,7",50,true,"帮助中心","帮助中心"));
		//long id,String cat_name,long parent_id,int sort_order,boolean is_show,String keywords,String cat_desc
	    list.forEach(each-> context.getArticleCategoryRepository().save(each));
	}
	
	private void createArticleList(){   //帮助中心 文章列表
		List<ArticleList> list  = new ArrayList<ArticleList>();
		list.add(new ArticleList("联系我们",1,false,false,50,"韩都联系方式","韩都联系方式韩都联系方式","http://handu.com","http://baidu.com/aa.jpeg",10,"感谢您支持韩都衣舍！您在购物的过程中，有没有遇到问题？若您有任何的意见或建议，请告诉我们。"));
		list.add(new ArticleList("诚聘英才",2,false,true,50,"诚聘英才","诚聘英才诚聘英才","http://handu.com","http://baidu.com/bb.gif",10,"感谢您支持韩都衣舍！您在购物的过程中，有没有遇到问题？若您有任何的意见或建议，请告诉我们。"));
		list.add(new ArticleList("媒体报道",3,false,false,50,"媒体报道","媒体报道媒体报道","http://handu.com","http://baidu.com/cc.png",10,"感谢您支持韩都衣舍！您在购物的过程中，有没有遇到问题？若您有任何的意见或建议，请告诉我们。"));
		list.add(new ArticleList("品牌故事",4,false,true,50,"品牌故事","品牌故事品牌故事","http://handu.com","http://baidu.com/dd.jpg",10,"感谢您支持韩都衣舍！您在购物的过程中，有没有遇到问题？若您有任何的意见或建议，请告诉我们。"));
	    list.forEach(each-> context.getArticleListRepository().save(each));
	}
	
	private void createAdPositionId(){		//广告位 	
		List<AdPositionId> list  = new ArrayList<AdPositionId>();
		list.add(new AdPositionId("首页-03-右侧","index_right" , BelongPage.INDEXPAGE,100 ,200 ,"Thymeleaf提供了一个用于整合Spring MVC的可选模块 "));
		list.add(new AdPositionId("商品详情页—左侧","detail_left" , BelongPage.DETAILSPAGE,150 ,200 ,"Thymeleaf提供了一个用于整合Spring MVC的可选模块 "));
		list.add(new AdPositionId("会员俱乐部-韩都积分-上方","jlb_up" , BelongPage.INDEXPAGE,120 ,180 ,"Thymeleaf提供了一个用于整合Spring MVC的可选模块 "));
		list.add(new AdPositionId("搜索页下方","search_down" , BelongPage.SEARCHPAGE,140 ,250,"Thymeleaf提供了一个用于整合Spring MVC的可选模块 "));
		list.add(new AdPositionId("分类页中间","cat_middle" , BelongPage.CATEGORYPAGE,110 ,300 ,"Thymeleaf提供了一个用于整合Spring MVC的可选模块 "));
		list.forEach(each-> context.getAdPositionIdRepository().save(each));
	}
	
	private void createAdvertiseList(){  //广告列表
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		List<AdvertiseList> list = new ArrayList<AdvertiseList>();   //http://www.taobao.com/
		try {
			list.add(new AdvertiseList("aa",MediaType.IMAGE,1,100 ,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"http://www.baidu.com" , "http://s.handu.com/images/201405/1400577643593368310.jpg",true ,"ymeleaf提供了一个用于整合Spring MVC的可选模块" , 1000));
			list.add(new AdvertiseList("bb",MediaType.IMAGE,2,100 ,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"http://www.baidu.com" , "http://s.handu.com/images/201405/1400577643593368310.jpg",true ,"ymeleaf提供了一个用于整合Spring MVC的可选模块" , 1000));
			list.add(new AdvertiseList("cc",MediaType.IMAGE,3,100 ,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"http://www.baidu.com" , "http://s.handu.com/images/201405/1400577643593368310.jpg",false ,"ymeleaf提供了一个用于整合Spring MVC的可选模块" , 1000));
			list.add(new AdvertiseList("dd",MediaType.IMAGE,4,100 ,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"http://www.baidu.com" , "http://s.handu.com/images/201405/1400577643593368310.jpg",false,"ymeleaf提供了一个用于整合Spring MVC的可选模块" , 1000));
			list.add(new AdvertiseList("ee",MediaType.IMAGE,5,100 ,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"http://www.baidu.com" , "http://s.handu.com/images/201405/1400577643593368310.jpg",false,"ymeleaf提供了一个用于整合Spring MVC的可选模块" , 1000));
			list.add(new AdvertiseList("ff",MediaType.IMAGE,1,100 ,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"http://www.baidu.com" , "http://s.handu.com/images/201405/1400577643593368310.jpg",true ,"ymeleaf提供了一个用于整合Spring MVC的可选模块" , 1000));
			list.add(new AdvertiseList("gg",MediaType.IMAGE,2,100 ,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"http://www.baidu.com" , "http://s.handu.com/images/201405/1400577643593368310.jpg",true ,"ymeleaf提供了一个用于整合Spring MVC的可选模块" , 1000));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		list.forEach(each -> context.getAdvertiseListRepository().save(each));
		
	}  
	
	private void createPostForFreeActivity(){  //包邮活动
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		List<PostForFreeActivity> list = new ArrayList<PostForFreeActivity>();   //http://www.taobao.com/
		try {
			list.add(new PostForFreeActivity("单品包邮11",PostForFreeType.SINGLEGOOD,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"ymeleaf提供了一个用于整合Spring MVC的可选模块"));
			list.add(new PostForFreeActivity("全场满200减50普通包邮",PostForFreeType.ORDER,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"ymeleaf提供了一个用于整合Spring MVC的可选模块"));
			list.add(new PostForFreeActivity("全场满200减50普通包邮",PostForFreeType.ORDER,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"ymeleaf提供了一个用于整合Spring MVC的可选模块"));
			list.add(new PostForFreeActivity("单品包邮22",PostForFreeType.SINGLEGOOD,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"ymeleaf提供了一个用于整合Spring MVC的可选模块"));
			list.add(new PostForFreeActivity("单品包邮33",PostForFreeType.SINGLEGOOD,sdf.parse("2014-06-01 10:00:00"), sdf.parse("2014-12-01 10:00:00"),"ymeleaf提供了一个用于整合Spring MVC的可选模块"));
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
		list.forEach(each -> context.getPostForFreeActivityRepository().save(each));
		
	}
	
	
	
	
 
 
	private void createTopics(){
        List<Topic> list = new ArrayList<>();


		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

		Date startDate1 = null;
		Date endDate1 = null;
		Date startDate2 = null;
		Date endDate2 = null;

		try {

			startDate1 = sdf.parse("2014-01-01 00:00:00");
			endDate1 = sdf.parse("2014-01-10 00:00:00");

			startDate2 = sdf.parse("2014-02-01 00:00:00");
			endDate2 = sdf.parse("2014-02-10 00:00:00");

		} catch (ParseException e) {

			e.printStackTrace();
		}
		list.add(new Topic("女装专题",    "文件名称1" ,startDate1, endDate1  ) );
		list.add(new Topic("双11专题页面", "文件名称2", startDate1, endDate1 ) );
		list.add(new Topic("手机推送专题",  "文件名称3",startDate1, endDate1 ) );
		list.add(new Topic("618专题页面", "文件名称4", startDate1, endDate1 ) );
		list.add(new Topic("清仓大甩卖",   "文件名称5",startDate1, endDate1 ) );
		list.add(new Topic("双12专题页面", "文件名称6" ,startDate1, endDate1 ) );
		list.add(new Topic("男人节题页面",  "文件名称7",startDate2, endDate2 ) );
		list.add(new Topic("61儿童节专题页面","文件名称8",startDate2, endDate2 ) );
		list.add(new Topic("教师节专题页面",  "文件名称9",startDate2, endDate2 ) );
		list.add(new Topic("端午节专题页面",  "文件名称10",startDate2, endDate2 ) );
		list.add(new Topic("春节专题页面",   "文件名称11", startDate2, endDate2 ) );

        for(Topic topic : list) {
            context.getTopicRepository().save(topic);
        }


	}
	
	
	private void createAttributes(){
		
		List<Attribute> list = new ArrayList<Attribute>();
		list.add(new Attribute("颜色", SelectType.SINGLE, "#ff0000,红色\n#0000ff,蓝色\n#98fb98,绿色\n#000000,黑色\n#888888,灰色\n#FFFFFF,白色\n#FF44AA,玫红色,\n#7700FF,紫色", 10));
		list.add(new Attribute("尺码", SelectType.SINGLE, "S\nM\nL",20));
		list.add(new Attribute("季节", SelectType.SINGLE,  "春季\n夏季\n秋季\n冬季",30));
		list.add(new Attribute("款式", SelectType.SINGLE,  "长款\n短款\n中长款",40));
		list.add(new Attribute("样式", SelectType.SINGLE, "韩版\n复古\n潮流",50));
		list.forEach(each -> context.getAttributeRepository().save(each));
	}
	
	private void createGoodsManage(){
		List<Goods> list = new ArrayList<Goods>();
			list.add(new Goods(1,5,"男士绅士休闲开衫格纹图案两侧口袋加厚马甲", "tx01", BigDecimal.valueOf(70),BigDecimal.valueOf(80),true, 10, "柏帅", 10));
			list.add(new Goods(2,4,"男装时尚休闲半开门襟修身长袖翻领纯色针织衫", "cq01", BigDecimal.valueOf(60),BigDecimal.valueOf(70), true, 20, "柏帅",10));
			list.add(new Goods(3,3,"女士字母图案长袖圆领套头休闲套装", "dk01", BigDecimal.valueOf(50),BigDecimal.valueOf(60), true, 30, "柏帅", 10));
			list.add(new Goods(4,2,"男士休闲套头纽扣半开襟牛仔拼接百搭衬衫", "mk01", BigDecimal.valueOf(40),BigDecimal.valueOf(50), true, 40, "柏帅", 10));
			list.add(new Goods(5,1,"女士长袖宽松条纹韩范儿T恤 ", "cx01", BigDecimal.valueOf(30),BigDecimal.valueOf(40), true, 50, "柏帅",10));
			list.add(new Goods(6,3,"女装简约休闲修身显瘦两件套长袖翻领衬衫无袖针织衫", "ck01", BigDecimal.valueOf(20),BigDecimal.valueOf(30), true, 60, "柏帅",10));
			list.add(new Goods(1,5,"女士黑色时尚简约英伦纯色平底短靴", "lyq01", BigDecimal.valueOf(10),BigDecimal.valueOf(20), true, 70, "柏帅", 10));
			list.add(new Goods(1,5,"女装帅气休闲长袖开衫翻领拼色拼接加厚外套", "lyq01", BigDecimal.valueOf(40),BigDecimal.valueOf(50), false, 70, "柏帅",10));
			list.add(new Goods(1,5,"韩版帅气休闲长袖开衫翻领拼色拼接加厚外套", "hb01", BigDecimal.valueOf(40),BigDecimal.valueOf(60), false, 70, "柏帅",10));
			list.add(new Goods(1,5,"时尚帅气休闲长袖开衫翻领拼色拼接加厚外套", "shd01", BigDecimal.valueOf(40),BigDecimal.valueOf(80), false, 70, "柏帅",10));
			list.add(new Goods(1,5,"劲霸帅气休闲长袖开衫翻领拼色拼接加厚外套", "jbd01", BigDecimal.valueOf(40),BigDecimal.valueOf(60), false, 70, "柏帅", 10));
	        list.add(new Goods(1,5,"劲霸帅气休闲长袖开衫翻领拼色拼接加厚外套2", "jbd02", BigDecimal.valueOf(40),BigDecimal.valueOf(60), false, 70, "柏帅", 10));
			for(Goods goods :list){
				context.getGoodsRepository().save(goods);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}

		
	}
	
	private void createSalesPromotion(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		List<SalesPromotion> list = new ArrayList<SalesPromotion>();
		try {
			list.add(new SalesPromotion("促销活动1", sdf.parse("2014-07-01 00:00:00"), sdf.parse("2014-08-01 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2014-07-01 00:00:00"), sdf.parse("2014-07-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
			list.add(new SalesPromotion("促销活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),  "11111"));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		list.forEach(each -> context.getSalesPromotionRepository().save(each));
	}
	
	private void createSecKillGroupBuy(){

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		List<SecKillGroupBuy> list = new ArrayList<SecKillGroupBuy>();
		try {
			list.add(new SecKillGroupBuy("秒杀活动1", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.SECKILL));
			list.add(new SecKillGroupBuy("团购活动2", sdf.parse("2013-02-01 00:00:00"), sdf.parse("2013-02-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.GROUPBUY));
			list.add(new SecKillGroupBuy("团购活动3", sdf.parse("2013-03-01 00:00:00"), sdf.parse("2013-03-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.GROUPBUY));
			list.add(new SecKillGroupBuy("团购活动4", sdf.parse("2013-04-01 00:00:00"), sdf.parse("2013-04-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.GROUPBUY));
			list.add(new SecKillGroupBuy("秒杀活动5", sdf.parse("2013-05-01 00:00:00"), sdf.parse("2013-05-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.SECKILL));
			list.add(new SecKillGroupBuy("秒杀活动6", sdf.parse("2013-06-01 00:00:00"), sdf.parse("2013-06-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.SECKILL));
			list.add(new SecKillGroupBuy("秒杀活动7", sdf.parse("2013-07-01 00:00:00"), sdf.parse("2013-07-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.SECKILL));
			list.add(new SecKillGroupBuy("秒杀活动8", sdf.parse("2013-08-01 00:00:00"), sdf.parse("2013-08-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.SECKILL));
			list.add(new SecKillGroupBuy("秒杀活动9", sdf.parse("2013-09-01 00:00:00"), sdf.parse("2013-09-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.SECKILL));
			list.add(new SecKillGroupBuy("秒杀活动10", sdf.parse("2013-10-01 00:00:00"), sdf.parse("2013-10-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.SECKILL));
			list.add(new SecKillGroupBuy("团购活动11", sdf.parse("2013-11-01 00:00:00"), sdf.parse("2013-11-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.GROUPBUY));
			list.add(new SecKillGroupBuy("团购活动12", sdf.parse("2013-12-01 00:00:00"), sdf.parse("2013-12-11 00:00:00"),10,  "11111", SecKillGroupBuy.SecKillGroupBuyStatus.GROUPBUY));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		list.forEach(each -> context.getSecKillGroupBuyRepository().save(each));
	}
	
	private void createActivities(){

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		List<Activities> list = new ArrayList<Activities>();
		try {
			list.add(new Activities("优惠活动1", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动2", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动3", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动4", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动5", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动6", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动7", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动8", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动9", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动10", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
			list.add(new Activities("优惠活动11", sdf.parse("2013-01-01 00:00:00"), sdf.parse("2013-01-11 00:00:00"), ActivitiesRange.ALL,BigDecimal.valueOf(0), BigDecimal.valueOf(100), ActivitiesMethods.DISCOUNT, ""));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		list.forEach(each -> context.getActivitiesRepository().save(each));
	}
	
	private void createGeneralInfos() {
		List<BrandGeneralInfo> list = new ArrayList<BrandGeneralInfo>();
		
		List<Brand> brands = context.getBrandRepository().findAll();
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		
		Date startDate1 = null;
		Date endDate1 = null;
		Date startDate2 = null;
		Date endDate2 = null;
		Date startDate3 = null;
		Date endDate3 = null;
		
		try {
			
			startDate1 = sdf.parse("2014-01-01 00:00:00");
			endDate1 = sdf.parse("2014-01-10 00:00:00");
			
			startDate2 = sdf.parse("2014-02-01 00:00:00");
			endDate2 = sdf.parse("2014-02-10 00:00:00");
			
			startDate3 = sdf.parse("2014-03-01 00:00:00");
			endDate3 = sdf.parse("2014-03-10 00:00:00");
		} catch (ParseException e) {
			
			e.printStackTrace();
		}
		
		
		list.add(new BrandGeneralInfo(brands.get(0).getId(), "content1", startDate1, endDate1, true));
		list.add(new BrandGeneralInfo(brands.get(1).getId(), "content2", startDate1, endDate1, true));
		list.add(new BrandGeneralInfo(brands.get(2).getId(), "content3", startDate1, endDate1, true));
		list.add(new BrandGeneralInfo(brands.get(3).getId(), "content4", startDate2, endDate2, true));
		list.add(new BrandGeneralInfo(brands.get(4).getId(), "content5", startDate3, endDate3, true));
		
		list.forEach(each -> context.getBrandGeneralInfoRepository().save(each));
		
	}
	
	
	private void createAdminControllers(){
		List<AdminControllerCategory> categories = new ArrayList<AdminControllerCategory>();
		categories.add(new AdminControllerCategory("首页"));
		categories.add(new AdminControllerCategory("商品管理"));
		categories.add(new AdminControllerCategory("会员管理"));
		categories.add(new AdminControllerCategory("促销管理"));
		categories.add(new AdminControllerCategory("文章管理"));
		
        categories.add(new AdminControllerCategory("订单管理"));
        categories.add(new AdminControllerCategory("广告管理"));
        categories.add(new AdminControllerCategory("系统管理"));

		categories.forEach(each -> context.getAdminControllerCategoryRepository().save(each));
		
		List<AdminControllerDescription> list = new ArrayList<AdminControllerDescription>();
		list.add(new AdminControllerDescription("Brand","品牌",categories.get(1).getId()));
		list.add(new AdminControllerDescription("Attribute","属性",categories.get(1).getId()));
		list.add(new AdminControllerDescription("BrandGeneralInfo","品牌通用信息",categories.get(1).getId()));
		
		list.add(new AdminControllerDescription("Category","分类",categories.get(1).getId()));
		list.add(new AdminControllerDescription("User","会员",categories.get(2).getId()));
		list.add(new AdminControllerDescription("UserRank","会员级别",categories.get(2).getId()));
		list.add(new AdminControllerDescription("UserLog","会员积分日志",categories.get(2).getId()));
		list.add(new AdminControllerDescription("Home","首页",categories.get(0).getId()));
		list.add(new AdminControllerDescription("SalesPromotion","促销活动",categories.get(3).getId()));
		list.add(new AdminControllerDescription("SecKillGroupBuy","秒杀团购",categories.get(3).getId()));
		list.add(new AdminControllerDescription("Activities","优惠活动",categories.get(3).getId()));
		list.add(new AdminControllerDescription("CreditPromotion","多倍积分",categories.get(3).getId()));
		list.add(new AdminControllerDescription("CreditPromotionGoods","多倍积分商品",categories.get(3).getId()));
		list.add(new AdminControllerDescription("CreditGoodsGoods","积分商城商品",categories.get(3).getId()));
		list.add(new AdminControllerDescription("PostForFreeActivity","包邮活动",categories.get(3).getId()));
		
		list.add(new AdminControllerDescription("ArticleCategory","文章分类",categories.get(4).getId()));
		list.add(new AdminControllerDescription("AdPositionId","广告位置",categories.get(6).getId()));
		
		list.add(new AdminControllerDescription("WorkLog","操作日志",categories.get(7).getId()));
		
		//list.add(new AdminControllerDescription("ArticleList","文章列表",categories.get(4).getId()));

        AdminControllerDescription comboAdminControllerDescription =
                new AdminControllerDescription("Combo","搭配套餐",
                        "index,add,edit,save,delete,view,goodsSearch",
                        "搭配套餐列表,添加套餐,套餐编辑,保存套餐,删除套餐,查看套餐,搭配套餐查询",
                        "搭配套餐列表,添加套餐,套餐编辑,保存套餐,删除套餐,查看套餐,搭配套餐查询");
        comboAdminControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(comboAdminControllerDescription);

        AdminControllerDescription topicControllerDescription = new AdminControllerDescription(
                "Topic",
                "专题",
                "index,add,list,edit,save,delete,updateContent,updateModules,updateGoods",
                "专题列表,专题添加,专题列表,专题编辑,专题保存,专题删除,专题内容,专题模块,专题模块商品",
                "专题列表,专题添加,专题列表,专题编辑,专题保存,专题删除,专题内容,专题模块,专题模块商品");
        topicControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(topicControllerDescription);
        
        AdminControllerDescription deliverAreaControllerDescription = new AdminControllerDescription(
                "DeliverArea",
                "配送区域",
                "index,add,list,edit,save,delete,searchRegion",
                "配送区域列表,配送区域添加,配送区域列表,配送区域编辑,配送区域保存,配送区域删除,查询地区",
                "配送区域列表,配送区域添加,配送区域列表,配送区域编辑,配送区域保存,配送区域删除,查询地区");
        deliverAreaControllerDescription.setCategoryId(categories.get(7).getId());
        list.add(deliverAreaControllerDescription);

        AdminControllerDescription deliverControllerDescription = new AdminControllerDescription(
                "Deliver",
                "配送方式",
                "index,add,list,edit,save,delete,setArea,saveAreas",
                "配送方式列表,配送方式添加,配送方式列表,配送方式编辑,配送方式保存,配送方式删除,设置区域,设置区域",
                "配送方式列表,配送方式添加,配送方式列表,配送方式编辑,配送方式保存,配送方式删除,设置区域,设置区域");
        deliverControllerDescription.setCategoryId(categories.get(7).getId());
        list.add(deliverControllerDescription);

        AdminControllerDescription orderInfoContollerDescription = new AdminControllerDescription(
        		"OrderInfo",
        		"订单列表", 
        		"index,list,edit,save,delete,view,operator,saveOperator",
        		"订单列表,订单列表,订单编辑,订单保存,订单删除,订单查看,操作订单,操作订单",
        		"订单列表,订单列表,订单编辑,订单保存,订单删除,订单查看,操作订单,操作订单");
        orderInfoContollerDescription.setCategoryId(categories.get(5).getId());
        list.add(orderInfoContollerDescription);

        AdminControllerDescription couponPromotionControllerDescription = new AdminControllerDescription(
                "CouponPromotion",
                "优惠券",
                "index,list,add,edit,save,delete,view,grant,deleteCoupon",
                "优惠券管理,优惠券管理,优惠券添加,优惠券编辑,优惠券保存,优惠券删除,优惠券查看,优惠券发放,优惠券删除",
                "优惠券管理,优惠券管理,优惠券添加,优惠券编辑,优惠券保存,优惠券删除,优惠券查看,优惠券发放,优惠券删除");
        couponPromotionControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(couponPromotionControllerDescription);

        AdminControllerDescription redPacketPromotionControllerDescription = new AdminControllerDescription(
                "RedPacketPromotion",
                "红包",
                "index,list,add,edit,save,delete,view,grant,deleteRedPacket",
                "红包管理,红包管理,红包添加,红包编辑,红包保存,红包删除,红包查看,红包发放,红包删除",
                "红包管理,红包管理,红包添加,红包编辑,红包保存,红包删除,红包查看,红包发放,红包删除");
        redPacketPromotionControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(redPacketPromotionControllerDescription);
        
        AdminControllerDescription cashCardPromotionControllerDescription = new AdminControllerDescription(
                "CashCardPromotion",
                "现金卡",
                "index,list,add,edit,save,delete,view,grant,deleteCashCard,log",
                "现金卡管理,现金卡管理,现金卡添加,现金卡编辑,现金卡保存,现金卡删除,现金卡查看,现金卡发放,现金卡删除,日志查看",
                "现金卡管理,现金卡管理,现金卡添加,现金卡编辑,现金卡保存,现金卡删除,现金卡查看,现金卡发放,现金卡删除,日志查看");
        cashCardPromotionControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(cashCardPromotionControllerDescription);
        
		AdminControllerDescription goodsControllerDescription = new AdminControllerDescription(
                "Goods",
                "商品列表",
                "index,list,add,edit,save,delete,update,indexTrash,deleteTrash,updateTrash,editBygoodsSN,verifyGoodsSN,verifySKuGoodsSN,saveSKU,match,saveMatch,goodsMatchableSearch,saveLine,editTitle,editTitleByConditions",
                "商品管理,商品管理,商品添加,商品编辑,商品保存,商品删除,商品更新,商品回收站,物理删除,商品还原,货号相同编辑,验证货号,验证货号,保存SKU,商品搭配管理,商品搭配管理,商品搭配查询,商品相册修改,促销标题管理,促销标题管理",
                "商品管理,商品管理,商品添加,商品编辑,商品保存,商品删除,商品更新,商品回收站,物理删除,商品还原,货号相同编辑,验证货号,验证货号,保存SKU,商品搭配管理,商品搭配管理,商品搭配查询,商品相册修改,促销标题管理,促销标题管理");
		goodsControllerDescription.setCategoryId(categories.get(1).getId());
        list.add(goodsControllerDescription);
        
        AdminControllerDescription albumControllerDescription = new AdminControllerDescription(
                "Album",
                "商品列表",
                "index,list,add,edit,save,delete,update,upload",
                "相册管理,相册管理,相册添加,相册编辑,相册保存,相册删除,商品更新,相册上传",
                "相册管理,相册管理,相册添加,相册编辑,相册保存,相册删除,商品更新,相册上传");
		albumControllerDescription.setCategoryId(categories.get(1).getId());
        list.add(albumControllerDescription);
        
        AdminControllerDescription creditGoodsControllerDescription = new AdminControllerDescription(
                "CreditGoods",
                "积分商品列表",
                "index,list,add,edit,save,delete,ajaxSearch",
                "积分商品管理,积分商品管理,积分商品添加,积分商品编辑,积分商品保存,积分商品删除,商品搜索",
                "积分商品管理,积分商品管理,积分商品添加,积分商品编辑,积分商品保存,积分商品删除,商品搜索");
        creditGoodsControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(creditGoodsControllerDescription);
        
		AdminControllerDescription articleControllerDescription = new AdminControllerDescription(
                "ArticleList",
                "帮助中心列表",
                "index,list,add,edit,save,delete,update",
                "帮助中心管理,帮助中心管理,文章添加,文章编辑,文章保存,文章删除,文章更新",
                "帮助中心管理,帮助中心管理,文章添加,文章编辑,文章保存,文章删除,文章更新");
		articleControllerDescription.setCategoryId(categories.get(4).getId());
        list.add(articleControllerDescription);  //createAdvertiseList
        
    	AdminControllerDescription advertiseListControllerDescription = new AdminControllerDescription(
                "AdvertiseList",
                "广告列表",
                "index,list,add,edit,save,delete,update",
                "广告列表管理,广告列表管理,广告添加,广告编辑,广告保存,广告删除,广告更新",
                "广告列表管理,广告列表管理,广告添加,广告编辑,广告保存,广告删除,广告更新");
    	advertiseListControllerDescription.setCategoryId(categories.get(6).getId());
        list.add(advertiseListControllerDescription); 
        
        AdminControllerDescription postForFreeActivityControllerDescription = new AdminControllerDescription(
                "PostForFreeActivity",
                "包邮活动列表",
                "index,list,add,edit,save,delete,singleGoods",
                "包邮活动列表管理,包邮活动列表管理,包邮活动添加,包邮活动编辑,包邮活动保存,包邮活动删除,包邮活动添加单品",
                "包邮活动列表管理,包邮活动列表管理,包邮活动添加,包邮活动编辑,包邮活动保存,包邮活动删除,包邮活动添加单品");
        postForFreeActivityControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(postForFreeActivityControllerDescription); 
        
        
        

        AdminControllerDescription postCardPromotionControllerDescription = new AdminControllerDescription(
                "PostCardPromotion",
                "包邮卡",
                "index,list,add,edit,save,delete,view,initGrant,grant,deletePostCard",
                "包邮卡管理,包邮卡管理,包邮卡添加,包邮卡编辑,包邮卡保存,包邮卡删除,包邮卡查看,包邮卡发放,包邮卡发放,包邮卡删除",
                "包邮卡管理,包邮卡管理,包邮卡添加,包邮卡编辑,包邮卡保存,包邮卡删除,包邮卡查看,包邮卡发放,包邮卡发放,包邮卡删除");
        postCardPromotionControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(postCardPromotionControllerDescription);
        
        AdminControllerDescription salesPromotionGoodsControllerDescription = new AdminControllerDescription(
                "SalesPromotionGoods",
                "促销活动商品",
                "index,list,add,edit,save,delete,ajaxsave,uploadgoods,deletegood",
                "促销商品管理,促销商品管理,促销商品添加,促销商品编辑,促销商品保存,促销商品删除,促销商品AJAX添加,批量上传促销商品,删除促销商品(活动ID加商品ID)",
                "促销商品管理,促销商品管理,促销商品添加,促销商品编辑,促销商品保存,促销商品删除,促销商品AJAX添加,批量上传促销商品,删除促销商品(活动ID加商品ID)");
        salesPromotionGoodsControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(salesPromotionGoodsControllerDescription);

        AdminControllerDescription secKillGroupBuyGoodsControllerDescription = new AdminControllerDescription(
                "SecKillGroupBuyGoods",
                "秒杀团购商品",
                "index,list,add,edit,save,delete,ajaxsave,uploadgoods,deletegood",
                "秒杀团购商品管理,秒杀团购商品管理,秒杀团购商品添加,秒杀团购商品编辑,秒杀团购商品保存,秒杀团购商品删除,秒杀团购商品AJAX添加,批量上传秒杀团购商品,删除秒杀团购商品(活动ID加商品ID)",
                "秒杀团购商品管理,秒杀团购商品管理,秒杀团购商品添加,秒杀团购商品编辑,秒杀团购商品保存,秒杀团购商品删除,秒杀团购商品AJAX添加,批量上传秒杀团购商品,删除秒杀团购商品(活动ID加商品ID)");
        secKillGroupBuyGoodsControllerDescription.setCategoryId(categories.get(3).getId());
        list.add(secKillGroupBuyGoodsControllerDescription);


 
		list.forEach(each -> context.getAdminControllerDescriptionRepository().save(each));
	}

    public void createCouponPromotions() {
        List<CouponPromotion> couponPromotionList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        Date date1 = null;
        Date date2 = null;
        Date date3 = null;
        Date date4 = null;

        try {
            date1 = sdf.parse("2014-01-01 00:00:00");
            date2 = sdf.parse("2014-01-02 00:00:00");
            date3 = sdf.parse("2014-01-03 00:00:00");
            date4 = sdf.parse("2014-01-04 00:00:00");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        couponPromotionList.add(new CouponPromotion("10元优惠劵1", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        couponPromotionList.add(new CouponPromotion("20元优惠劵2", BonusPromotion.GrantType.ORDER, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        couponPromotionList.add(new CouponPromotion("30元优惠劵3", BonusPromotion.GrantType.GOOD, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        couponPromotionList.add(new CouponPromotion("40元优惠劵4", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));
        couponPromotionList.add(new CouponPromotion("50元优惠劵5", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(50.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注5"));
        couponPromotionList.add(new CouponPromotion("10元优惠劵6", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        couponPromotionList.add(new CouponPromotion("20元优惠劵7", BonusPromotion.GrantType.ORDER, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        couponPromotionList.add(new CouponPromotion("30元优惠劵8", BonusPromotion.GrantType.GOOD, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        couponPromotionList.add(new CouponPromotion("40元优惠劵9", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));
        couponPromotionList.add(new CouponPromotion("50元优惠劵10", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(50.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注5"));
        couponPromotionList.add(new CouponPromotion("10元优惠劵11", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        couponPromotionList.add(new CouponPromotion("20元优惠劵12", BonusPromotion.GrantType.ORDER, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        couponPromotionList.add(new CouponPromotion("30元优惠劵13", BonusPromotion.GrantType.GOOD, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        couponPromotionList.add(new CouponPromotion("40元优惠劵14", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));


        CouponPromotion couponPromotion1 = new CouponPromotion("60元优惠劵15", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(60.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注6");
        couponPromotion1.setGrantNum(50L);
        couponPromotionList.add(couponPromotion1);

        for(CouponPromotion couponPromotion : couponPromotionList) {
            context.getCouponPromotionRepository().save(couponPromotion);
        }
    }

    public void createRedPacketPromotions() {
        List<RedPacketPromotion> redPacketPromotionList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        Date date1 = null;
        Date date2 = null;
        Date date3 = null;
        Date date4 = null;

        try {
            date1 = sdf.parse("2014-01-01 00:00:00");
            date2 = sdf.parse("2014-01-02 00:00:00");
            date3 = sdf.parse("2014-01-03 00:00:00");
            date4 = sdf.parse("2014-01-04 00:00:00");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        redPacketPromotionList.add(new RedPacketPromotion("10元红包1", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        redPacketPromotionList.add(new RedPacketPromotion("20元红包2", BonusPromotion.GrantType.ORDER, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        redPacketPromotionList.add(new RedPacketPromotion("30元红包3", BonusPromotion.GrantType.GOOD, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        redPacketPromotionList.add(new RedPacketPromotion("40元红包4", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));
        redPacketPromotionList.add(new RedPacketPromotion("50元红包5", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(50.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注5"));
        redPacketPromotionList.add(new RedPacketPromotion("10元红包6", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        redPacketPromotionList.add(new RedPacketPromotion("20元红包7", BonusPromotion.GrantType.ORDER, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        redPacketPromotionList.add(new RedPacketPromotion("30元红包8", BonusPromotion.GrantType.GOOD, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        redPacketPromotionList.add(new RedPacketPromotion("40元红包9", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));
        redPacketPromotionList.add(new RedPacketPromotion("50元红包10", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(50.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注5"));
        redPacketPromotionList.add(new RedPacketPromotion("10元红包11", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        redPacketPromotionList.add(new RedPacketPromotion("20元红包12", BonusPromotion.GrantType.ORDER, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        redPacketPromotionList.add(new RedPacketPromotion("30元红包13", BonusPromotion.GrantType.GOOD, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        redPacketPromotionList.add(new RedPacketPromotion("40元红包14", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));


        RedPacketPromotion redPacketPromotion1 = new RedPacketPromotion("60元红包15", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(60.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注6");
        redPacketPromotion1.setGrantNum(50L);
        redPacketPromotionList.add(redPacketPromotion1);

        for(RedPacketPromotion redPacketPromotion : redPacketPromotionList) {
            context.getRedPacketPromotionRepository().save(redPacketPromotion);
        }
    }
    
    public void createCashCardPromotions() {
        List<CashCardPromotion> cashCardPromotionList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        Date date1 = null;
        Date date2 = null;
        Date date3 = null;
        Date date4 = null;

        try {
            date1 = sdf.parse("2014-01-01 00:00:00");
            date2 = sdf.parse("2014-01-02 00:00:00");
            date3 = sdf.parse("2014-01-03 00:00:00");
            date4 = sdf.parse("2014-01-04 00:00:00");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cashCardPromotionList.add(new CashCardPromotion("10元现金卡1", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        cashCardPromotionList.add(new CashCardPromotion("20元现金卡2", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        cashCardPromotionList.add(new CashCardPromotion("30元现金卡3", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        cashCardPromotionList.add(new CashCardPromotion("40元现金卡4", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));
        cashCardPromotionList.add(new CashCardPromotion("50元现金卡5", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(50.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注5"));
        cashCardPromotionList.add(new CashCardPromotion("10元现金卡6", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        cashCardPromotionList.add(new CashCardPromotion("20元现金卡7", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        cashCardPromotionList.add(new CashCardPromotion("30元现金卡8", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        cashCardPromotionList.add(new CashCardPromotion("40元现金卡9", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));
        cashCardPromotionList.add(new CashCardPromotion("50元现金卡10", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(50.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注5"));
        cashCardPromotionList.add(new CashCardPromotion("10元现金卡11", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(10.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注1"));
        cashCardPromotionList.add(new CashCardPromotion("20元现金卡12", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(20.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注2"));
        cashCardPromotionList.add(new CashCardPromotion("30元现金卡13", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(30.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注3"));
        cashCardPromotionList.add(new CashCardPromotion("40元现金卡14", BonusPromotion.GrantType.UNDERLINE, "0,1", new BigDecimal(40.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注4"));


        CashCardPromotion cashCardPromotion1 = new CashCardPromotion("60元现金卡15", BonusPromotion.GrantType.USER, "0,1", new BigDecimal(60.0), new BigDecimal(100.0), date1,date2,date3,date4, "1,2,3,4", "备注6");
        cashCardPromotion1.setGrantNum(50L);
        cashCardPromotion1.setUsedNum(50L);
        cashCardPromotionList.add(cashCardPromotion1);

        for(CashCardPromotion cashCardPromotion : cashCardPromotionList) {
            context.getCashCardPromotionRepository().save(cashCardPromotion);
        }
    }


    public void createPostCardPromotions() {
        List<PostCardPromotion> postCardPromotionList = new ArrayList<>();
        postCardPromotionList.add(new PostCardPromotion("春季包邮卡1",3L,6L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("季度包邮卡2",3L,6L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("终身包邮卡3",200L,30L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("至尊包邮卡4",12L,30L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("VIP包邮卡5",6L,15L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("春季包邮卡6",3L,6L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("季度包邮卡7",3L,6L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("终身包邮卡8",200L,30L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("至尊包邮卡9",12L,30L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("VIP包邮卡10",6L,15L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("季度包邮卡11",3L,6L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("终身包邮卡12",200L,30L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("至尊包邮卡13",12L,30L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("VIP包邮卡14",6L,15L,0L,0L));
        postCardPromotionList.add(new PostCardPromotion("VIP包邮卡15",6L,15L,50L,50L));

        for(PostCardPromotion postCardPromotion : postCardPromotionList) {
            context.getPostCardPromotionRepository().save(postCardPromotion);
        }
    }

    public void createCoupons() {

        CouponPromotion couponPromotion = context.getCouponPromotionRepository().findOne(15L);
        for(int i=0;i<50; i++) {
            Coupon coupon = new Coupon();
            coupon.setUserId(1L);
            coupon.setBonusPromotionId(couponPromotion.getId());
            coupon.save(coupon);
        }
    }

    public void createRedPackets() {

        RedPacketPromotion redPacketPromotion = context.getRedPacketPromotionRepository().findOne(15L);
        for(int i=0;i<50; i++) {
            RedPacket redPacket = new RedPacket();
            redPacket.setUserId(1L);
            redPacket.setBonusPromotionId(redPacketPromotion.getId());
            redPacket.save(redPacket);
        }
    }
    
    public void createCashCards() {

        CashCardPromotion cashCardPromotion = context.getCashCardPromotionRepository().findOne(15L);
        for(int i=0;i<50; i++) {
            CashCard cashCard = new CashCard();
            cashCard.setUserId(1L);
            cashCard.setBonusPromotionId(cashCardPromotion.getId());
            cashCard.setLeftPrice(cashCardPromotion.getBonusPrice());
            cashCard.save(cashCard);
        }
    }

    public void createPostCards() {

        PostCardPromotion postCardPromotion = context.getPostCardPromotionRepository().findOne(15L);
        for(int i=0;i<50; i++) {
            PostCard postCard = new PostCard();
            postCard.setUserId(1L);
            postCard.setPostCardPromotionId(postCardPromotion.getId());
            postCard.save(postCard);
        }
    }
    public void createOrders(){
        List<User> users = context.getUserRepository().findAll();
        List<Goods> goods = context.getGoodsRepository().findAll();
        List<OrderInfo> parents = new ArrayList<OrderInfo>();
        List<OrderInfo> childs = new ArrayList<OrderInfo>();
        List<OrderDetail> items = new ArrayList<OrderDetail>();
        parents.add(new OrderInfo(generateOrderNumber(), users.get(0).getId(),users.get(0).getName(), null, "顺丰快递", new Date(), null,
                 OrderSource.WEBPAGE,OrderInfo.Purchasing.ISPURCHASING,OrderStatus.UNCONFIRMED, PaymentStatus.NONPAYMENT,DeliveryStatus.NONSHIPPED,
                "张恒强", "山东省济南市历城区", "15069187133", "250000",
                BigDecimal.valueOf(40*10), BigDecimal.valueOf(40*10), null,null,null,null,null,null,BrandType.COMMON));
        context.getOrderInfoRepository().save(parents.get(0));
        parents.add(new OrderInfo(generateOrderNumber(), users.get(2).getId(),users.get(2).getName(), null, "顺丰快递", new Date(), null,
                  OrderSource.WEBPAGE,OrderInfo.Purchasing.ISPURCHASING,OrderStatus.CONFIRMED, PaymentStatus.NONPAYMENT, DeliveryStatus.NONSHIPPED,
                 "张恒强", "山东省济南市历城区", "15069187133", "250000",
                BigDecimal.valueOf(650), BigDecimal.valueOf(650), null,null,null,null,null,null,null));
        context.getOrderInfoRepository().save(parents.get(1));
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -3);
        parents.add(new OrderInfo(generateOrderNumber(),users.get(3).getId(),users.get(3).getName(), "支付宝", "顺丰快递", c.getTime(), c.getTime(),
                 OrderSource.WEBPAGE, OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CONFIRMED, PaymentStatus.ACCOUNTPAID, DeliveryStatus.NONSHIPPED,
                 "张恒强", "山东省济南市历城区", "15069187133", "250000",
                BigDecimal.valueOf(60*10), BigDecimal.valueOf(60*10), BigDecimal.valueOf(60*10),
                null,null,null,null,null,BrandType.AGENT));
        context.getOrderInfoRepository().save(parents.get(2));
        parents.add(new OrderInfo(generateOrderNumber(),users.get(2).getId(),users.get(2).getName(), "支付宝", "顺丰快递", new Date(), new Date(),
                 OrderSource.WAP, OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CONFIRMED, PaymentStatus.ACCOUNTPAID, DeliveryStatus.SHIPPED,
                "张恒强", "山东省济南市历城区", "15069187133", "250000",
                BigDecimal.valueOf(20*10), BigDecimal.valueOf(20*10), BigDecimal.valueOf(20*10)
                ,null,null,null,null,null,BrandType.COMMON));
        context.getOrderInfoRepository().save(parents.get(3));
        parents.add(new OrderInfo(generateOrderNumber(),users.get(0).getId(),users.get(0).getName(), "支付宝", "顺丰快递", new Date(), new Date(),
                OrderSource.MOBILEPHONE, OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CANCEL, PaymentStatus.NONPAYMENT, DeliveryStatus.NONSHIPPED,
                "张恒强", "山东省济南市历城区", "15069187133", "250000",
                BigDecimal.valueOf(50*10), BigDecimal.valueOf(50*10), BigDecimal.valueOf(0),
                null,null,null,null,null,BrandType.AGENT));
        context.getOrderInfoRepository().save(parents.get(4));
        parents.add(new OrderInfo(generateOrderNumber(),users.get(1).getId(),users.get(1).getName(), "网上银联", "圆通速递", new Date(), new Date(),
                OrderSource.WAP,OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CONFIRMED,
                PaymentStatus.ACCOUNTPAID, DeliveryStatus.SHIPPED,
                "张恒强", "山东省济南市历城区", "15069187133", "250000",
                BigDecimal.valueOf(260), BigDecimal.valueOf(250),
                BigDecimal.valueOf(230),BigDecimal.valueOf(10),BigDecimal.valueOf(10),
                BigDecimal.valueOf(10), BigDecimal.valueOf(10), BigDecimal.valueOf(20),null));
        context.getOrderInfoRepository().save(parents.get(5));
        parents.add(new OrderInfo(generateOrderNumber(),users.get(1).getId(),users.get(1).getName(), "网上银联", "圆通速递", new Date(), new Date(),
                 OrderSource.WAP,OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CONFIRMED, PaymentStatus.ACCOUNTPAID, DeliveryStatus.SHIPPED,
                "张恒强", "山东省济南市历城区", "15069187133","250000",
                BigDecimal.valueOf(500), BigDecimal.valueOf(500), BigDecimal.valueOf(500),
                null,null,null,null,null,BrandType.AGENT));
        context.getOrderInfoRepository().save(parents.get(6));

        //临时添加三条未确认 未付款 未发货  无子订单的记录
        for(int i=0;i<3;i++){
            parents.add(new OrderInfo(generateOrderNumber(), users.get(0).getId(),users.get(0).getName(), null, "顺丰快递", new Date(), null,
                    OrderSource.WEBPAGE,OrderInfo.Purchasing.ISPURCHASING,OrderStatus.UNCONFIRMED, PaymentStatus.NONPAYMENT,DeliveryStatus.NONSHIPPED,
                    "张恒强", "山东省济南市历城区", "15069187133", "250000",
                    BigDecimal.valueOf(40*10), BigDecimal.valueOf(40*10), null,null,null,null,null,null,BrandType.COMMON));
            context.getOrderInfoRepository().save(parents.get(7+i));
        }

        //临时添加四条未确认 未付款 未发货  有子订单的记录
        for(int i=0;i<4;i++){
            parents.add(new OrderInfo(generateOrderNumber(), users.get(0).getId(),users.get(0).getName(), null, "顺丰快递", new Date(), null,
                    OrderSource.WEBPAGE,OrderInfo.Purchasing.ISPURCHASING,OrderStatus.UNCONFIRMED, PaymentStatus.NONPAYMENT,DeliveryStatus.NONSHIPPED,
                    "张恒强", "山东省济南市历城区", "15069187133", "250000",
                    BigDecimal.valueOf(650), BigDecimal.valueOf(650), null,null,null,null,null,null,null));
            context.getOrderInfoRepository().save(parents.get(10+i));
        }

        for(int i =0;i<10;i++){
        	context.getOrderInfoRepository().save(new OrderInfo("测试翻页订单请勿操作0"+i,users.get(1).getId(),users.get(1).getName(), "网上银联", "圆通速递", new Date(), new Date(),
                OrderSource.WAP,OrderInfo.Purchasing.ISPURCHASING,OrderStatus.CONFIRMED, PaymentStatus.ACCOUNTPAID, DeliveryStatus.SHIPPED,
                "张恒强", "山东省济南市历城区", "15069187133","250000",
                BigDecimal.valueOf(500), BigDecimal.valueOf(500), BigDecimal.valueOf(500),
                null,null,null,null,null,BrandType.AGENT));
        }
        for(int i =0;i<10;i++){
            context.getOrderInfoRepository().save(new OrderInfo("测试翻页订单请勿操作1"+i,users.get(1).getId(),users.get(1).getName(), "网上银联", "圆通速递", new Date(), new Date(),
                    OrderSource.WAP,OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CONFIRMED, PaymentStatus.NONPAYMENT, DeliveryStatus.NONSHIPPED,
                    "张恒强", "山东省济南市历城区", "15069187133","250000",
                    BigDecimal.valueOf(500), BigDecimal.valueOf(500), BigDecimal.valueOf(500),
                    null,null,null,null,null,BrandType.AGENT));
        }
        for(int i =0;i<10;i++){
            context.getOrderInfoRepository().save(new OrderInfo("测试翻页订单请勿操作2"+i,users.get(1).getId(),users.get(1).getName(), "网上银联", "圆通速递", new Date(), new Date(),
                    OrderSource.WAP,OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CONFIRMED, PaymentStatus.ACCOUNTPAID, DeliveryStatus.NONSHIPPED,
                    "张恒强", "山东省济南市历城区", "15069187133","250000",
                    BigDecimal.valueOf(500), BigDecimal.valueOf(500), BigDecimal.valueOf(500),
                    null,null,null,null,null,BrandType.AGENT));
        }
        for(int i =0;i<10;i++){
            context.getOrderInfoRepository().save(new OrderInfo("测试翻页订单请勿操作3"+i,users.get(1).getId(),users.get(1).getName(), "网上银联", "圆通速递", new Date(), new Date(),
                    OrderSource.WAP,OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CANCEL, PaymentStatus.NONPAYMENT, DeliveryStatus.NONSHIPPED,
                    "张恒强", "山东省济南市历城区", "15069187133","250000",
                    BigDecimal.valueOf(500), BigDecimal.valueOf(500), BigDecimal.valueOf(500),
                    null,null,null,null,null,BrandType.AGENT));
        }
        for(int i =0;i<10;i++){
            context.getOrderInfoRepository().save(new OrderInfo("测试翻页订单请勿操作4"+i,users.get(1).getId(),users.get(1).getName(), "网上银联", "圆通速递", new Date(), new Date(),
                    OrderSource.WAP,OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.CONFIRMED, PaymentStatus.NONPAYMENT, DeliveryStatus.SHIPPED,
                    "张恒强", "山东省济南市历城区", "15069187133","250000",
                    BigDecimal.valueOf(500), BigDecimal.valueOf(500), BigDecimal.valueOf(500),
                    null,null,null,null,null,BrandType.AGENT));
        }
        for(int i =0;i<10;i++){
            context.getOrderInfoRepository().save(new OrderInfo("测试翻页订单请勿操作5"+i,users.get(1).getId(),users.get(1).getName(), "网上银联", "圆通速递", new Date(), new Date(),
                    OrderSource.WAP,OrderInfo.Purchasing.NOTPURCHASING,OrderStatus.UNCONFIRMED, PaymentStatus.NONPAYMENT, DeliveryStatus.NONSHIPPED,
                    "张恒强", "山东省济南市历城区", "15069187133","250000",
                    BigDecimal.valueOf(500), BigDecimal.valueOf(500), BigDecimal.valueOf(500),
                    null,null,null,null,null,BrandType.AGENT));
        }
        //parents.forEach(each -> context.getOrderInfoRepository().save(each));

        childs.add(new OrderInfo(parents.get(1).getOrderNumber()+"01", parents.get(1).getOrderNumber(),
                 DeliveryStatus.NONSHIPPED, null, null,
                BigDecimal.valueOf(70*5), BigDecimal.valueOf(70*5), null,BrandType.AGENT));
        childs.add(new OrderInfo(parents.get(1).getOrderNumber()+"02", parents.get(1).getOrderNumber(),
                DeliveryStatus.NONSHIPPED, null, null,
                BigDecimal.valueOf(60*5), BigDecimal.valueOf(60*5), null,BrandType.AGENT));
        

        childs.add(new OrderInfo(parents.get(5).getOrderNumber()+"01", parents.get(5).getOrderNumber(),
                 DeliveryStatus.SHIPPED, new Date(), "123124123131",
                BigDecimal.valueOf(160), BigDecimal.valueOf(150), BigDecimal.valueOf(130),
                BigDecimal.valueOf(10),BigDecimal.valueOf(10), BigDecimal.valueOf(10),
                BigDecimal.valueOf(10), BigDecimal.valueOf(20),BrandType.COMMON));
        childs.add(new OrderInfo(parents.get(5).getOrderNumber()+"02", parents.get(5).getOrderNumber(),
                 DeliveryStatus.SHIPPED, new Date(), "123124123131",
                BigDecimal.valueOf(20*5), BigDecimal.valueOf(20*5), BigDecimal.valueOf(20*5),BrandType.COMMON));

        //四条父订单的子订单（各两个 下标从4开始 4 5/6 7/8 9/10 11）父 10 11 12 13
        for(int i=0;i<4;i++){
            childs.add(new OrderInfo(parents.get(10+i).getOrderNumber()+"01", parents.get(10+i).getOrderNumber(),
                    DeliveryStatus.NONSHIPPED, null, null,
                    BigDecimal.valueOf(70*5), BigDecimal.valueOf(70*5), null,BrandType.AGENT));
            childs.add(new OrderInfo(parents.get(10+i).getOrderNumber()+"02", parents.get(10+i).getOrderNumber(),
                    DeliveryStatus.NONSHIPPED, null, null,
                    BigDecimal.valueOf(60*5), BigDecimal.valueOf(60*5), null,BrandType.AGENT));
        }


        childs.forEach(each -> context.getOrderInfoRepository().save(each));
        
        items.add(new OrderDetail(10, goods.get(3).getId(), parents.get(0).getOrderNumber()));
        
        items.add(new OrderDetail(5, goods.get(0).getId(), childs.get(0).getOrderNumber()));
        items.add(new OrderDetail(5, goods.get(1).getId(), childs.get(1).getOrderNumber()));
        
        items.add(new OrderDetail(10, goods.get(1).getId(), parents.get(2).getOrderNumber()));
        
        items.add(new OrderDetail(10, goods.get(5).getId(), parents.get(3).getOrderNumber()));
        
        items.add(new OrderDetail(10, goods.get(2).getId(), parents.get(4).getOrderNumber()));
        
        items.add(new OrderDetail(5, goods.get(4).getId(), childs.get(2).getOrderNumber()));
        items.add(new OrderDetail(5, goods.get(5).getId(), childs.get(3).getOrderNumber()));

        items.add(new OrderDetail(10, goods.get(2).getId(), parents.get(6).getOrderNumber()));

        //临时添加三条未确认 未付款 未发货  无子订单的记录
        for(int i=0;i<3;i++){
            items.add(new OrderDetail(10,goods.get(3).getId(),parents.get(7+i).getOrderNumber()));
        }
        for(int i=0;i<8;i++){
            if (i%2==0){
                items.add(new OrderDetail(5,goods.get(0).getId(),childs.get(4+i).getOrderNumber()));
            }else{
                items.add(new OrderDetail(5,goods.get(1).getId(),childs.get(4+i).getOrderNumber()));
            }

        }
        items.forEach(each -> context.getOrderDetailRepository().save(each));
    }
    
    private String generateOrderNumber(){
        DecimalFormat df = new DecimalFormat("0000");
        String ordernumber = new SimpleDateFormat("yyyyMMddHHmm").format(new Date())+df.format(new Random().nextInt(10000));
        while(context.getOrderInfoRepository().findByOrderNumber(ordernumber).size()>0){
            ordernumber = generateOrderNumber();
        }
        return ordernumber;
    }

    @SuppressWarnings("unchecked")
	public void createRegions() {
        Yaml yaml = new Yaml();
        Reader reader = null;
        //File file = new File("core/src/main/java/com/handu/luna/core/domain/data/regions.yaml");
        List<Region> regionList = null;
        try {
        	//String file = getClass().getResourceAsStream("data/regions.yaml").getFile();
            //reader = new FileReader(getClass().getResourceAsStream("data/regions.yaml"));
            regionList = yaml.loadAs(getClass().getResourceAsStream("data/regions.yaml"), List.class);
        } catch (Exception e) {
        	logger.debug("read file error",e);
        } finally {
            if (null != reader) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    reader = null;
                }

            }
        }
        if(regionList == null) {

        } else {
            for (Region region : regionList) {
                context.getRegionRepository().saveAndFlush(region);
            }
        }

    }

    public void createDeliverAreas() {

        List<DeliverArea> deliverAreaList = new ArrayList<>();
        DeliverArea deliverArea1 = new DeliverArea("非港澳台地区","非港澳台地区",BigDecimal.valueOf(80.0));
        DeliverArea deliverArea2 = new DeliverArea("华北六省一市","华北六省一市",BigDecimal.valueOf(60.0));
        DeliverArea deliverArea3 = new DeliverArea("华北六省一市","华北六省一市",BigDecimal.valueOf(50.0));
        DeliverArea deliverArea4 = new DeliverArea("华北六省一市","华北六省一市",BigDecimal.valueOf(40.0));
        DeliverArea deliverArea5 = new DeliverArea("华北六省一市","华北六省一市",BigDecimal.valueOf(30.0));

        deliverAreaList.add(deliverArea1);
        deliverAreaList.add(deliverArea2);
        deliverAreaList.add(deliverArea3);
        deliverAreaList.add(deliverArea4);
        deliverAreaList.add(deliverArea5);

        for(DeliverArea deliverArea : deliverAreaList) {
            context.getDeliverAreaRepository().save(deliverArea);
        }

    }

    public void createDelivers() {

        List<Deliver> deliverList = new ArrayList<>();
        deliverList.add(new Deliver("配送方式一", "配送描述一", "0,1"));
        deliverList.add(new Deliver("配送方式二", "配送描述二","0,1"));
        deliverList.add(new Deliver("配送方式三", "配送描述三","0,1"));
        deliverList.add(new Deliver("配送方式四", "配送描述四","0,1"));
        deliverList.add(new Deliver("配送方式五", "配送描述五","0,1"));
        deliverList.add(new Deliver("配送方式六", "配送描述六","0,1"));
        deliverList.add(new Deliver("配送方式七", "配送描述七","0,1"));
        deliverList.add(new Deliver("配送方式八", "配送描述八","0,1"));
        deliverList.add(new Deliver("配送方式九", "配送描述九","0,1"));
        deliverList.add(new Deliver("配送方式十", "配送描述十","0,1"));
        deliverList.add(new Deliver("配送方式十一", "配送描述十一","0,1"));
        deliverList.add(new Deliver("配送方式十二", "配送描述十二","0,1"));

        for (Deliver deliver : deliverList) {
            context.getDeliverRepository().save(deliver);
        }

    }

    public void createOperator() {

        List<Operator> operators = new ArrayList<Operator>();
        operators.add(new Operator("admin","123456","超级管理员"));
        operators.add(new Operator("zhangwen","123456","张文"));
        for(Operator operator : operators) {
            context.getOperatorRepository().save(operator);
        }

    }   
    
    
}
